package prv.pursuivant.core.impl;

import java.util.Collections;
import java.util.List;

import prv.pursuivant.core.AchievType;

/**
 * Abstract achievement type.
 * 
 * Achievement type means the class of achievement (like "The Immortal"), not
 * the instance (like "Kwinto achieved "The Immortal" on 08/03/2009").
 * 
 * @author Kwinto
 * @see prv.pursuivant.core.impl.AchievementImpl
 */

public abstract class AbstractAchievType implements AchievType {

	/**
	 * Name of the achievement type
	 */
	private final String name;

	/**
	 * Children (criteria) of this achievement - list of ids.
	 */
	private final List<String> criteria;

	/**
	 * The only constructor - for subclasses.
	 * 
	 * @param kind
	 * @param name
	 * @param id
	 * @param subId
	 * @param criteria
	 */
	protected AbstractAchievType(String name, List<String> criteria) {
		this.name = name;
		// This is to make sure noone will mess with the list.
		this.criteria = Collections.unmodifiableList(criteria);
	}

	/**
	 * Compares only id
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		else if (obj == null)
			return false;
		else if (this.getClass().equals(obj.getClass())) {
			AbstractAchievType achiev = (AbstractAchievType) obj;
			return this.getId().equals(achiev.getId());
		} else
			return false;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return getId().hashCode();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see prv.pursuivant.core.achievtypes.AchievType#getName()
	 */
	public String getName() {
		return this.name;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see prv.pursuivant.core.achievtypes.AchievType#getCriteria()
	 */	
	public List<String> getCriteria() {
		if (this.criteria == null)
			return Collections.emptyList(); 
		return this.criteria;
	}

	@Override
	public String toString() {
		return getKind() + ":" + getId();
	}

}
